Type TVector
	Field _x#,_y#
	
	Method copy(v:TVector)
		_x = v._x
		_y = v._y
	End Method
	
	Method Set(x#, y#)
		_x = x; _y = y
	End Method
		
	Method add( v:TVector )
		_x :+ v._x
		_y :+ v._y
	End Method
	
	Method sub( v:TVector )
		_x :- v._x
		_y :- v._y
	End Method
	
	Method mult( s# )
		_x :* s
		_y :* s
	End Method

	Method div( s# )
		_x :/ s
		_y :/ s
	End Method
		
	Method DotProduct:Float( v:TVector )
		Return _x * v._x + _y * v._y
	End Method
	
	Method magnitude:Float( )
		Return Sqr( _x*_x + _y*_y )
	End Method
	
	Method normalize:Float( )
		Local m# = magnitude()
		If( m > 0 )
			Local rlen# = 1.0 / m
			_x:*rlen
			_y:*rlen
		EndIf
	End Method
	
	Method limit(Maxi#)
		If magnitude() > Maxi
			normalize()
			mult(Maxi)
		EndIf
	End Method
	
	Method heading2D:Float()
		Return -ATan2(-_y, _x)
	End Method
End Type

Function VectorCreate:TVector( x# , y# )
	Local t:TVector = New TVector
	t._x = x
	t._y = y
	Return t
End Function

Function VectorClone:TVector( v:TVector )
	Local t:TVector = New TVector
	t._x = v._x
	t._y = v._y
	Return t
End Function

Function VectorDistance:Float( a:TVector, b:TVector  )
	Local dx# = a._x - b._x
	Local dy# = a._y - b._y
	Return Sqr( dx*dx + dy*dy ) 
End Function

Function VectorDistanceSquared:Float( a:TVector, b:TVector  )
	Local dx# = a._x - b._x
	Local dy# = a._y - b._y
	Return ( dx*dx + dy*dy ) 
End Function


Function VectorAdd:TVector( a:TVector, b:TVector  )
	Local tmp:TVector = New TVector
	tmp._x = a._x + b._x
	tmp._y = a._y + b._y
	Return tmp
End Function


Function VectorSub:TVector( a:TVector, b:TVector  )
	Local tmp:TVector = New TVector
	tmp._x = a._x - b._x
	tmp._y = a._y - b._y
	Return tmp
End Function
